package com.lottery.initData;

import com.lottery.dto.Changlong;
import com.lottery.dto.MessageTube;
import com.lottery.dto.SscOddsShow;
import com.lottery.entity.LotteryOdds;
import com.lottery.obtainData.SscYesWinningFactory.InitUtils;
import com.lottery.service.qiuqiu.JedisClient;
import com.lottery.utils.messageTube.MessageFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

import java.sql.Timestamp;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

@Component
/**
 * 初始化数据字典
 */
public class InitData {
    @Resource
    private MessageFactory messageFactory;

    @Resource
    private InitUtil initUtil;

    @Autowired
    private JedisClient jedis;

    public static List<String> oddDecorateList = new ArrayList<>();

    public static Map<String,Map<String,MessageTube>> MESSAGE_GROUP  = new HashMap<>();

    //支付渠道状态码解释
    public static Map<Integer,String> RECHARGE_CANAL = new HashMap<>();

    //lottey对应的赔率集合
    public static  Map<Integer,Map<String,Map<Integer,LinkedHashMap<String,LotteryOdds>>>> LOTTEY_REF_LOTTEYODD =new HashMap<>();

    //ssc赔率MAP集合
    public static Map<String,Map<Integer,LinkedHashMap<String,LotteryOdds>>> SSC_ODD_MAP = new HashMap<>();
    //BJSC赔率MAP集合
    public static Map<String,Map<Integer,LinkedHashMap<String,LotteryOdds>>> BJSC_ODD_MAP = new HashMap<>();

    //ssc开奖集合
    public static Map<Integer,List<String>> SSC_WINRESULT_MAP = new HashMap<>();

    //bjsc开奖集合
    public static Map<Integer,List<String>> BJSC_WINRESULT_MAP = new HashMap<>();

    //SSC下注规则对应玩法Id
    public static  Map<String,Integer> SSC_BETRULE_REF_PLAYWAYID= new HashMap<>();
    //BJSC下注规则对应玩法Id
    public static  Map<String,Integer> BJSC_BETRULE_REF_PLAYWAYID= new HashMap<>();


    //SSC长龙信息处理(SSC_STORE_CHANGLONF信息存放的地方 SSC_SORT_CHANGLONG排序后存放的地方 )
    public static List<Changlong> SSC_STORE_CHANGLONG = new ArrayList<>(30);

    public static  LinkedList<Changlong> SSC_SORT_CHANGLONG = new LinkedList<>();

    //北京赛车长龙信息处理(BJSC_STORE_CHANGLONG信息存放的地方 BJSC_SORT_CHANGLONG排序后存放的地方 )
    public static List<Changlong> BJSC_STORE_CHANGLONG = new ArrayList<>(30);

    public static  LinkedList<Changlong> BJSC_SORT_CHANGLONG = new LinkedList<>();

    //在线人数统计
    public static Map<String,Map<Integer,Long>> ONLINE_MAP = new HashMap<>();

    //心跳包
    public static Map<Integer, String> SSO_MAP = new ConcurrentHashMap<Integer, String>();

    //机器人的在线人数
    public static Map<String,Integer>  ROBOT_ONLINE_NUM = new HashMap<>();
    
    public static Map<String, Timestamp> effctiveTimes=new HashMap<String, Timestamp>();



    private final Logger logger = LoggerFactory.getLogger(this.getClass());




    @PostConstruct
    public void init() {

        oddDecorateList.add("前");
        oddDecorateList.add("中");
        oddDecorateList.add("后");

        //项目启动初始化信息通道
        messageFactory.InitMessagetube();



        RECHARGE_CANAL.put(1,"银行卡");
        RECHARGE_CANAL.put(2,"支付宝");
        RECHARGE_CANAL.put(3,"微信");

        //初始化LOTTEY_REF_LOTTEYODDmap集合
        LOTTEY_REF_LOTTEYODD.put(1,SSC_ODD_MAP);
        LOTTEY_REF_LOTTEYODD.put(3,BJSC_ODD_MAP);

        //初始化ssc_ODD_MAP
        initUtil.initODD_MAP(1);
        initUtil.initODD_MAP(3);



        //初始化每期下注的最大最小值
        initUtil.initMaxMin();
        //初始化下注map
        initUtil.initBetRule();
        //初始化sscstoreMap;
        initUtil.initSscChangLong();
        initUtil.initBjscChangLong();
        initUtil.initEffctiveTimes();
    }




//    //创建定时任务运行体系
//    public class ListenRedisMethod extends TimerTask {
//        @Override
//        public void run() {
//            logger.debug("listenSscOddChange timer start");
//            if (jedis.get("sscOddChange").equals("1")) {
//                initUtils.getSscOddsMap(1);
//            }
//            logger.debug("listenSscOddChange timer end");
//        }
//    }
//
//    //定时监听redis状态(没半个小时监听一次)
//    public void listenSscOddChange() {
//        logger.debug("listenSscOddChange start");
//        try {
//            ListenRedisMethod ss = new ListenRedisMethod();
//            SimpleDateFormat sdf = new SimpleDateFormat("yy-MM-dd HH:mm:ss");
//            String dateString = "2018-3-14 15:11:00";
//            Date date = null;
//            date = sdf.parse(dateString);
//            timer.schedule(ss, date, 1000 * 60 * 30);
//            //timer.schedule(ss,date,1000*10);
//        } catch (ParseException e) {
//            logger.debug("listenSscOddChange e,{}", e);
//            e.printStackTrace();
//        }
//        logger.debug("listenSscOddChange start");
//    }


}
